package com.liufh.controller;

import com.liufh.service.ResumeService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: liufh
 * @create: 2022-01-08 21:54
 **/
@RestController
@RequestMapping("/resume")
public class ResumeController {

    @Autowired
    private ResumeService resumeService;

    @Value("${server.port}")
    private Integer port;

    /**
     * 测试多微服务组情况下的Hystrix Turbine聚合监控
     */
//    @HystrixCommand(
//            // 线程池标识，要保持唯一，不唯一的话就共用了
//            threadPoolKey = "findDefaultResumeState",
//            // 线程池细节属性配置
//            threadPoolProperties = {
//                    @HystrixProperty(name = "coreSize", value = "1"), // 线程数
//                    @HystrixProperty(name = "maxQueueSize", value = "20") // 等待队列长度
//            },
//            // commandProperties熔断的一些细节属性配置
//            commandProperties = {
//                    // 每一个属性都是一个HystrixProperty
//                    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "10000")
//            }
//    )
    @GetMapping("/openstate/{userId}")
    public Integer findDefaultResumeState(@PathVariable Long userId) {
//        try {
//            Thread.sleep(5000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println("====findDefaultResumeState userId:" + userId);
//        return resumeService.findDefaultResumeByUserId(userId).getIsOpenResume();
        return port;
    }

}
